package topcoder.srm428;

public class ThePalindrome {
	public int find(String s) {
		if (s.length() == 1)
			return 1;
		if (isPalin(s))
			return s.length();

		StringBuilder sb = new StringBuilder(s);
		StringBuilder reverse = new StringBuilder(
				s.substring(0, s.length() - 1)).reverse();

		int best = sb.length() + reverse.length();

		for (int i = 0; i < reverse.length(); i++) {
			StringBuilder t = new StringBuilder(sb);
			t.append(reverse.substring(i));
			if (isPalin(t.toString()))
				best = t.length();
		}
		return best;

	}

	private boolean isPalin(String s) {
		for (int i = 0; i < s.length() / 2; i++) {
			if (s.charAt(i) != s.charAt(s.length() - i - 1))
				return false;
		}

		return true;
	}

	public static void main(String[] args) {
		ThePalindrome tp = new ThePalindrome();
		System.out.println(tp.find("abdfhdyrbdbsdfghjkllkjhgfds"));
	}

}
